package cn.tedu.fy.pethome.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import lombok.Data;

import java.util.Date;
import java.util.Map;
@Data
public class JwtUtil {

    private static final String SECRET_KEY ="312321312";
    private static int minute = 200;





    public static Claims parseJwt(String jwt){
        return Jwts.parser().setSigningKey(SECRET_KEY).parseClaimsJws(jwt).getBody();
    }

    public static String buildJwt(Map<String,Object> claims){
        System.out.println("@@@@@");
        return Jwts.builder()
                .setHeaderParam("typ","jwt")
                .setHeaderParam("alg","HS256")
                .setClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis()+minute*60*1000))
                .signWith(SignatureAlgorithm.HS256,SECRET_KEY)
                .compact();
    }



}
